//
//  Team9ExpertTalkViewController.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/22.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9ExpertTalkViewController.h"
#import "Team9ExpertTalkCell.h"
#import "Team9JQHeader.h"



@interface Team9ExpertTalkViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSArray *array;

@end

@implementation Team9ExpertTalkViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);
    self.tableView.tableFooterView = [UIView new];
    [self createData];
//    NSLog(@"%@", _url);
}
#pragma mark tableView methods for protols
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Team9WorkReviewsModel *model = self.array[indexPath.row];
    CGFloat height = [Team9Tool heightByFloatSize:12 * WIDTH / 375 width:WIDTH - 20 With:model.content] + [Team9Tool heightByFloatSize:12 * WIDTH / 375 width:WIDTH - 40 With:model.col_info];
    if (!model.col_photos) {
        return 85 + WIDTH / 375 * 40 + height;
    } else return 95 + WIDTH / 375 * 140 + height;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"talkCell";
    Team9ExpertTalkCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[Team9ExpertTalkCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    Team9WorkReviewsModel *model = self.array[indexPath.row];
    cell.vc = self;
    cell.model = model;
//    NSLog(@"%@", model.user_nick);
    return cell;
}
- (void)createData{
    [JQAFNetworkTool getUrl:self.url success:^(id result) {
        self.array = [Team9WorkReviewsModel baseModelByArr:result[@"data"][@"user_home_review_list"][@"reviews"]];
//        [[self tableView] reloadData];
    }];
}
- (void)setArray:(NSArray *)array
{
    if (_array != array) {
        _array = array;
        [self.tableView reloadData];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
